Skip to content

Reloadable dochandles - #385

Merged
paulsonnentag merged 7 commits into
mainfrom
reloadable-dochandles
Jul 27, 2026
Merged

Reloadable dochandles#385
paulsonnentag merged 7 commits into
mainfrom
reloadable-dochandles

Conversation

@paulsonnentag

@paulsonnentag paulsonnentag commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Goal

Previously, when we resolved doc handles in a draft, we only did this once. Switching branches or scrubbing through history required remounting the editor every time to re-resolve the doc handle. This PR makes the resolution reactive, so you don’t lose UI state when switching branches, and scrubbing becomes much smoother.

Implementation

In patchwork-system we wrap repo in a generic proxy that translates repo.find into "repo:handle-descriptor" request that other providers can respond to. A handle descriptor looks like this:

export type DocHandleDescriptor = {
  url: AutomergeUrl;
  cloneUrl?: AutomergeUrl;
};

By default, a document URL maps to itself, but providers can implement custom mappings. For example, a draft creates a clone of each document it contains; when a document is requested within the draft, the provider responds with the clone’s URL. The repo turns the returned doc handle descriptor into a doc handle that looks like the original (its url still reports the original), but reads and writes are delegated to the clone.

This PR makes the doc handle emit an artificial change event when it’s remapped to another doc, for example when the user switches drafts. To an editor, a branch switch looks like any other document change.

One exception: for editors that implement undo/redo, like tldraw and CodeMirror, the branch switch needs to reset the history stack. We solve this with the scopeReplaced flag introduced with sub doc handles: any artificial change event triggered by a remapping sets scopeReplaced = true.

@netlify

netlify Bot commented Jul 24, 2026

Copy link
Copy Markdown

Deploy Preview for gaiosub ready!

Name Link
🔨 Latest commit f48fdb6
🔍 Latest deploy log https://app.netlify.com/projects/gaiosub/deploys/6a673c52443b17000870b3f7
😎 Deploy Preview https://deploy-preview-385--gaiosub.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions

github-actions Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

🪡 Patchwork

Torn down.

@paulsonnentag
paulsonnentag requested a review from chee July 27, 2026 13:01
@paulsonnentag
paulsonnentag marked this pull request as ready for review July 27, 2026 13:02
@paulsonnentag
paulsonnentag merged commit eed5a2c into main Jul 27, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants